/***********************************************************************************************
* DISCLAIMER
************************************************************************************************/
/*""FILE COMMENT""******************************************************************************
 * System Name  : FLASH driver software
 * File Name    : w25q.h
 * Version      : 
 * Contents     : FLASH driver header file
 * Customer     : Standard
 * Model        : None
 * CPU          : 
 * Compiler     : 
 * OS           : ---
 * Programmer   : 
 * Note         : 
 ***********************************************************************************************
 * History      : Date          Author          Comment
 *""FILE COMMENT END""**************************************************************************/
#ifndef __FLASH_H__
#define __FLASH_H__

/* These types must be 8-bit integer */
typedef char			int8_t;
typedef unsigned char	uint8_t;
/* These types must be 16-bit integer */
typedef short	        int16_t;
typedef unsigned short	uint16_t;



/************************************************************************************************/
/*  Definitions                                                                                 */
/************************************************************************************************/
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*                         Please define resources of each user system.                         */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*----------------------------------------------------------------------------------------------*/
/*   Define number of required serial FLASH devices.(1~N devices)                               */
/*   Define the device number in accordance with the number of serial FLASH devices             */
/*   to be connected.                                                                           */
/*----------------------------------------------------------------------------------------------*/
/* Define no. of devices */
#define FLASH_DEV_NUM           1                       /* 1devices                             */  /** SET **/

/* Define no. of slots */
#define FLASH_DEV0              0                       /* Device 0                             */  /** SET **/
#define FLASH_DEV1              1                       /* Device 1                             */  /** SET **/


/*----------------------------------------------------------------------------------------------*/
/*   Define the serial FLASH device.                                                            */
/*----------------------------------------------------------------------------------------------*/

//#define M25P05A                                       /* 512kbit  ( 64kByte)                  */  /** SET **/
//#define M25P10A                                       /* 1Mbit    ( 128kByte)                 */  /** SET **/
#define M25P20                                      /* 2Mbit    ( 256kByte)                 */  /** SET **/
//#define M25P40                                        /* 4Mbit    ( 512kByte)                 */  /** SET **/
//#define M25P16                                        /* 16Mbit   ( 2MByte)                   */  /** SET **/
//#define M25P32                                        /* 32Mbit   ( 4MByte)                   */  /** SET **/
//#define M25P64                                        /* 64Mbit   ( 8MByte)                   */  /** SET **/


/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*                              Do not change the following data.                               */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*----------- Definitions of return value ------------*/
#define FLASH_OK                (error_t)( 0)           /* Successful operation                 */
#define FLASH_ERR_PARAM         (error_t)(-1)           /* Parameter error                      */
#define FLASH_ERR_HARD          (error_t)(-2)           /* Hardware error                       */
#define FLASH_ERR_OTHER         (error_t)(-7)           /* Other error                          */


/*------------- Definitions of log type --------------*/
#define FLASH_LOG_ERR           1                       /* Log type : Error                     */


/*--------------- Definitions of flag ----------------*/
#define FLASH_TRUE              (uint8_t)0x01           /* Flag "ON"                            */
#define FLASH_FALSE             (uint8_t)0x00           /* Flag "OFF"                           */


/*------ Definitions of write-protection status ------*/
#define FLASH_WP_NONE           (uint8_t)0x00           /* None setting                         */

/*------------ Definitions of erase type  ------------*/
#define FLASH_B_ERASE           (uint8_t)0x00           /*Bulk erase                            */
#define FLASH_S_ERASE           (uint8_t)0x01           /*Sector erase                          */

/*-------- Definitions of device information ---------*/

#ifdef M25P05A
#define FLASH_MEM_SIZE          (uint32_t)65536         /*  64kByte (512kbit)                   */
#define FLASH_SECT_ADDR         (uint32_t)0xffff8000    /* Sector address setting               */
#define FLASH_WPAG_SIZE         (uint32_t)256           /* Page size when writing               */
#define FLASH_ADDR_SIZE         (uint8_t)3              /* Address size(Byte)                   */
#define FLASH_WP_WHOLE_MEM      (uint8_t)0x03           /* Whole memory WP setting              */
#endif  /* #ifdef M25P05A */

#ifdef M25P10A
#define FLASH_MEM_SIZE          (uint32_t)131072        /*  128kByte    (1Mbit)                 */
#define FLASH_SECT_ADDR         (uint32_t)0xffff8000    /* Sector address setting               */
#define FLASH_WPAG_SIZE         (uint32_t)256           /* Page size when writing               */
#define FLASH_ADDR_SIZE         (uint8_t)3              /* Address size(Byte)                   */
#define FLASH_WP_WHOLE_MEM      (uint8_t)0x03           /* Whole memory WP setting              */
#endif  /* #ifdef M25P10A */

#ifdef M25P20
#define FLASH_MEM_SIZE          (uint32_t)262144        /*  256kByte    (2Mbit)                 */
#define FLASH_SECT_ADDR         (uint32_t)0xffff0000    /* Sector address setting               */
#define FLASH_WPAG_SIZE         (uint32_t)256           /* Page size when writing               */
#define FLASH_ADDR_SIZE         (uint8_t)3              /* Address size(Byte)                   */
#define FLASH_WP_WHOLE_MEM      (uint8_t)0x03           /* Whole memory WP setting              */
#endif  /* #ifdef M25P20 */

#ifdef M25P40
#define FLASH_MEM_SIZE          (uint32_t)524288        /*  512kByte    (4Mbit)                 */
#define FLASH_SECT_ADDR         (uint32_t)0xffff0000    /* Sector address setting               */
#define FLASH_WPAG_SIZE         (uint32_t)256           /* Page size when writing               */
#define FLASH_ADDR_SIZE         (uint8_t)3              /* Address size(Byte)                   */
#define FLASH_WP_WHOLE_MEM      (uint8_t)0x07           /* Whole memory WP setting              */
#endif  /* #ifdef M25P40 */

#ifdef M25P16
#define FLASH_MEM_SIZE          (uint32_t)2097152       /*  2MByte  (16Mbit)                    */
#define FLASH_SECT_ADDR         (uint32_t)0xffff0000    /* Sector address setting               */
#define FLASH_WPAG_SIZE         (uint32_t)256           /* Page size when writing               */
#define FLASH_ADDR_SIZE         (uint8_t)3              /* Address size(Byte)                   */
#define FLASH_WP_WHOLE_MEM      (uint8_t)0x07           /* Whole memory WP setting              */
#endif  /* #ifdef M25P16 */

#ifdef M25P32
#define FLASH_MEM_SIZE          (uint32_t)4194304       /*  4MByte  (32Mbit)                    */
#define FLASH_SECT_ADDR         (uint32_t)0xffff0000    /* Sector address setting               */
#define FLASH_WPAG_SIZE         (uint32_t)256           /* Page size when writing               */
#define FLASH_ADDR_SIZE         (uint8_t)3              /* Address size(Byte)                   */
#define FLASH_WP_WHOLE_MEM      (uint8_t)0x07           /* Whole memory WP setting              */
#endif  /* #ifdef M25P32 */

#ifdef M25P64
#define FLASH_MEM_SIZE          (uint32_t)8388608       /*  8MByte  (64Mbit)                    */
#define FLASH_SECT_ADDR         (uint32_t)0xffff0000    /* Sector address setting               */
#define FLASH_WPAG_SIZE         (uint32_t)256           /* Page size when writing               */
#define FLASH_ADDR_SIZE         (uint8_t)3              /* Address size(Byte)                   */
#define FLASH_WP_WHOLE_MEM      (uint8_t)0x07           /* Whole memory WP setting              */
#endif  /* #ifdef M25P64 */

#define FLASH_CMD_SIZE          (uint8_t)1              /* Command size(Byte)                   */
#define FLASH_STSREG_SIZE       (uint16_t)1             /* Status register size(Byte)           */
#define FLASH_IDDATA_SIZE       (uint16_t)3             /* ID data size(Byte)                   */
#define FLASH_ESIG_SIZE         (uint16_t)1             /* Electronic Signature size(Byte)      */



/************************************************************************************************/
/*  Unions                                                                                      */
/************************************************************************************************/


/************************************************************************************************/
/*  Structs                                                                                     */
/************************************************************************************************/


/************************************************************************************************/
/*  Externs                                                                                     */
/************************************************************************************************/


/************************************************************************************************/
/*  Macros                                                                                      */
/************************************************************************************************/


/************************************************************************************************/
/*  Prototypes                                                                                  */
/************************************************************************************************/
error_t SPI_FLASH_Init_Driver(void);                  /* FLASH driver initialization          */
error_t SPI_FLASH_Read_Status(uint8_t DevNo, uint8_t FAR* pStatus);   /* Read status          */
error_t SPI_FLASH_Write_Protect(uint8_t DevNo, uint8_t WpSts);        /* Set write-protection */
error_t SPI_FLASH_Read_Data(uint8_t DevNo, uint32_t RAddr, uint32_t RCnt, uint8_t FAR* pData);
                                                                        /* Read data            */
error_t SPI_FLASH_Write_Data(uint8_t DevNo, uint32_t WAddr, uint32_t WCnt, uint8_t FAR* pData);
                                                                        /* Write data           */
error_t SPI_FLASH_BulkErase(uint8_t DevNo);                           /* Erase all data       */
error_t SPI_FLASH_SectorErase(uint8_t DevNo, uint32_t EAddr);         /* Erase sector data    */
error_t SPI_FLASH_DeepPDown(uint8_t DevNo);                           /* Deep power down      */
error_t SPI_FLASH_ReleaseDeepPDown(uint8_t DevNo, uint8_t FAR* pData);/* Release deep power down  */
error_t SPI_FLASH_ReadID(uint8_t DevNo, uint8_t FAR* pData);          /* ID read              */

#endif /* __FLASH_H__ */

/* End of File */
